using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class MainMenuPage : UIPanel
{
    [SerializeField]
    private Button AttackPower;
    [SerializeField]
    private Button ThrownSize;
    [SerializeField]
    private Button AttackPenetrate;
    [SerializeField]
    private Button ThrownSpeed;
    [SerializeField]
    private Button CoinButton;
    [SerializeField]
    private Text AttackPowerText;
    [SerializeField]
    private Text ThrownSizeText;
    [SerializeField]
    private Text AttackPenetrateText;
    [SerializeField]
    private Text ThrownSpeedText;
    [SerializeField]
    private Text CoinButtonText;
    void Awake()
    {
        UIManager.Instance.AddPanel(PanelId.MainMenu, this);
    }
    void OnEnable()
    {
        Main.Instance.gameStatus = GameStatus.Pause;
        UpdateInfo();
    }
    public void Upgrade(int upgradeType)
    {
        Main.Instance.saveData.Upgrade((UpgradeType)upgradeType);
        UpdateInfo();

    }
    public void UpdateInfo()
    {
        CoinButtonText.text = Main.Instance.saveData.Coin.ToString();
        if ((Main.Instance.saveData.PowerLevel + 1) < 10 && ((Main.Instance.saveData.PowerLevel + 1) * 100) > Main.Instance.saveData.Coin)
        {
            AttackPowerText.color = Color.red;
        }
        else
        {
            AttackPowerText.color = Color.white;
        }
        if ((Main.Instance.saveData.PowerLevel + 1) < 10)
        {
            AttackPowerText.text = ((Main.Instance.saveData.PowerLevel + 1) * 100).ToString();
        }
        else
        {
            AttackPowerText.text = "Max";
        }
        if ((Main.Instance.saveData.SizeLevel + 1) < 10 && ((Main.Instance.saveData.SizeLevel + 1) * 100) > Main.Instance.saveData.Coin)
        {
            ThrownSizeText.color = Color.red;
        }
        else
        {
            ThrownSizeText.color = Color.white;
        }
        if ((Main.Instance.saveData.SizeLevel + 1) < 10)
        {
            ThrownSizeText.text = ((Main.Instance.saveData.SizeLevel + 1) * 100).ToString();
        }
        else
        {
            ThrownSizeText.text = "Max";
        }
        if ((Main.Instance.saveData.PenetrateLevel + 1) < 10 && ((Main.Instance.saveData.PenetrateLevel + 1) * 100) > Main.Instance.saveData.Coin)
        {
            AttackPenetrateText.color = Color.red;
        }
        else
        {
            AttackPenetrateText.color = Color.white;
        }
        if ((Main.Instance.saveData.PenetrateLevel + 1) < 10)
        {
            AttackPenetrateText.text = ((Main.Instance.saveData.PenetrateLevel + 1) * 100).ToString();
        }
        else
        {
            AttackPenetrateText.text = "Max";
        }
        if ((Main.Instance.saveData.SpeedLevel + 1) < 10 && ((Main.Instance.saveData.SpeedLevel + 1) * 100) > Main.Instance.saveData.Coin)
        {
            ThrownSpeedText.color = Color.red;
        }
        else
        {
            ThrownSpeedText.color = Color.white;
        }
        if ((Main.Instance.saveData.SpeedLevel + 1) < 10)
            ThrownSpeedText.text = ((Main.Instance.saveData.SpeedLevel + 1) * 100).ToString();
        else
        {
            ThrownSpeedText.text = "Max";
        }
    }
    public void OpenShopPanel()
    {
        UIManager.Instance.CreateOrOpen(PanelId.CoinShop);
    }
    public override void Show()
    {
        //AudioManager.Instance.ResumeBGM();
        transform.DOScale(1f, 0f);
        base.Show();
    }
    public override void Hide()
    {
        //AudioManager.Instance.PauseBGM();
        transform.DOScale(0f, 0f);
        base.Hide();
    }
    public void BackSence()
    {
        SceneManager.LoadScene(1);
    }
}
